<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    
    <title>infoitem &mdash; GOZERWAVE v0.1 BETA documentation</title>
    <link rel="stylesheet" href="../_static/default.css" type="text/css" />
    <link rel="stylesheet" href="../_static/pygments.css" type="text/css" />
    <script type="text/javascript">
      var DOCUMENTATION_OPTIONS = {
        URL_ROOT:    '../',
        VERSION:     '0.1 BETA',
        COLLAPSE_MODINDEX: false,
        FILE_SUFFIX: '.html',
        HAS_SOURCE:  true
      };
    </script>
    <script type="text/javascript" src="../_static/jquery.js"></script>
    <script type="text/javascript" src="../_static/doctools.js"></script>
    <link rel="top" title="GOZERWAVE v0.1 BETA documentation" href="../index.html" />
    <link rel="next" title="rss" href="rss.html" />
    <link rel="prev" title="gcalc" href="gcalc.html" /> 
  </head>
  <body>
    <div class="related">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="../genindex.html" title="General Index"
             accesskey="I">index</a></li>
        <li class="right" >
          <a href="../modindex.html" title="Global Module Index"
             accesskey="M">modules</a> |</li>
        <li class="right" >
          <a href="rss.html" title="rss"
             accesskey="N">next</a> |</li>
        <li class="right" >
          <a href="gcalc.html" title="gcalc"
             accesskey="P">previous</a> |</li>
        <li><a href="../index.html">GOZERWAVE v0.1 BETA documentation</a> &raquo;</li> 
      </ul>
    </div>  

    <div class="document">
      <div class="documentwrapper">
        <div class="bodywrapper">
          <div class="body">
            
  <div class="section" id="infoitem">
<h1>infoitem<a class="headerlink" href="#infoitem" title="Permalink to this headline">¶</a></h1>
<div class="section" id="module-waveplugs.infoitem">
<h2>description<a class="headerlink" href="#module-waveplugs.infoitem" title="Permalink to this headline">¶</a></h2>
<p>information items .. use !learn &lt;item&gt; is &lt;description&gt; to add an item .. 
use !? &lt;item&gt; to query the infoitems database.</p>
<dl class="class">
<dt id="waveplugs.infoitem.InfoItem">
<em class="property">class </em><tt class="descclassname">waveplugs.infoitem.</tt><tt class="descname">InfoItem</tt><big>(</big><em>parent=None</em>, <em>key_name=None</em>, <em>_app=None</em>, <em>**kwds</em><big>)</big><a class="headerlink" href="#waveplugs.infoitem.InfoItem" title="Permalink to this definition">¶</a></dt>
<dd><p>Bases: <tt class="xref docutils literal"><span class="pre">google.appengine.ext.db.Expando</span></tt></p>
<dl class="attribute">
<dt id="waveplugs.infoitem.InfoItem.channel">
<tt class="descname">channel</tt><a class="headerlink" href="#waveplugs.infoitem.InfoItem.channel" title="Permalink to this definition">¶</a></dt>
<dd>A textual property, which can be multi- or single-line.</dd></dl>

<dl class="attribute">
<dt id="waveplugs.infoitem.InfoItem.createtime">
<tt class="descname">createtime</tt><a class="headerlink" href="#waveplugs.infoitem.InfoItem.createtime" title="Permalink to this definition">¶</a></dt>
<dd><p>The base class of all of our date/time properties.</p>
<p>We handle common operations, like converting between time tuples and
datetime instances.</p>
</dd></dl>

<dl class="attribute">
<dt id="waveplugs.infoitem.InfoItem.creator">
<tt class="descname">creator</tt><a class="headerlink" href="#waveplugs.infoitem.InfoItem.creator" title="Permalink to this definition">¶</a></dt>
<dd>A textual property, which can be multi- or single-line.</dd></dl>

<dl class="attribute">
<dt id="waveplugs.infoitem.InfoItem.description">
<tt class="descname">description</tt><a class="headerlink" href="#waveplugs.infoitem.InfoItem.description" title="Permalink to this definition">¶</a></dt>
<dd>A textual property, which can be multi- or single-line.</dd></dl>

<dl class="attribute">
<dt id="waveplugs.infoitem.InfoItem.item">
<tt class="descname">item</tt><a class="headerlink" href="#waveplugs.infoitem.InfoItem.item" title="Permalink to this definition">¶</a></dt>
<dd>A textual property, which can be multi- or single-line.</dd></dl>

<dl class="attribute">
<dt id="waveplugs.infoitem.InfoItem.public">
<tt class="descname">public</tt><a class="headerlink" href="#waveplugs.infoitem.InfoItem.public" title="Permalink to this definition">¶</a></dt>
<dd>A boolean property.</dd></dl>

</dd></dl>

<dl class="class">
<dt id="waveplugs.infoitem.InfoItemsDb">
<em class="property">class </em><tt class="descclassname">waveplugs.infoitem.</tt><tt class="descname">InfoItemsDb</tt><a class="headerlink" href="#waveplugs.infoitem.InfoItemsDb" title="Permalink to this definition">¶</a></dt>
<dd><p>Bases: <a title="(in Python v2.7)" class="reference external" href="http://docs.python.org/dev/library/functions.html#object"><tt class="xref docutils literal"><span class="pre">object</span></tt></a></p>
<p>information items</p>
<dl class="method">
<dt id="waveplugs.infoitem.InfoItemsDb.add">
<tt class="descname">add</tt><big>(</big><em>item</em>, <em>description</em>, <em>userhost</em>, <em>ttime</em>, <em>channel=''</em>, <em>name=''</em><big>)</big><a class="headerlink" href="#waveplugs.infoitem.InfoItemsDb.add" title="Permalink to this definition">¶</a></dt>
<dd>add an item</dd></dl>

<dl class="method">
<dt id="waveplugs.infoitem.InfoItemsDb.delete">
<tt class="descname">delete</tt><big>(</big><em>indexnr</em><big>)</big><a class="headerlink" href="#waveplugs.infoitem.InfoItemsDb.delete" title="Permalink to this definition">¶</a></dt>
<dd>delete item with indexnr.</dd></dl>

<dl class="method">
<dt id="waveplugs.infoitem.InfoItemsDb.get">
<tt class="descname">get</tt><big>(</big><em>item</em><big>)</big><a class="headerlink" href="#waveplugs.infoitem.InfoItemsDb.get" title="Permalink to this definition">¶</a></dt>
<dd>get infoitems.</dd></dl>

<dl class="method">
<dt id="waveplugs.infoitem.InfoItemsDb.searchdescr">
<tt class="descname">searchdescr</tt><big>(</big><em>search</em><big>)</big><a class="headerlink" href="#waveplugs.infoitem.InfoItemsDb.searchdescr" title="Permalink to this definition">¶</a></dt>
<dd>search descriptions.</dd></dl>

<dl class="method">
<dt id="waveplugs.infoitem.InfoItemsDb.searchitem">
<tt class="descname">searchitem</tt><big>(</big><em>search</em><big>)</big><a class="headerlink" href="#waveplugs.infoitem.InfoItemsDb.searchitem" title="Permalink to this definition">¶</a></dt>
<dd>search items.</dd></dl>

<dl class="method">
<dt id="waveplugs.infoitem.InfoItemsDb.size">
<tt class="descname">size</tt><big>(</big><big>)</big><a class="headerlink" href="#waveplugs.infoitem.InfoItemsDb.size" title="Permalink to this definition">¶</a></dt>
<dd>return number of items</dd></dl>

</dd></dl>

<dl class="function">
<dt id="waveplugs.infoitem.handle_addinfoitem">
<tt class="descclassname">waveplugs.infoitem.</tt><tt class="descname">handle_addinfoitem</tt><big>(</big><em>bot</em>, <em>ievent</em><big>)</big><a class="headerlink" href="#waveplugs.infoitem.handle_addinfoitem" title="Permalink to this definition">¶</a></dt>
<dd>learn &lt;keyword&gt; is &lt;description&gt; .. add information item</dd></dl>

<dl class="function">
<dt id="waveplugs.infoitem.handle_forget">
<tt class="descclassname">waveplugs.infoitem.</tt><tt class="descname">handle_forget</tt><big>(</big><em>bot</em>, <em>ievent</em><big>)</big><a class="headerlink" href="#waveplugs.infoitem.handle_forget" title="Permalink to this definition">¶</a></dt>
<dd>forget &lt;keyword&gt; &lt;txttomatch&gt; .. remove information item where         description matches txt given.</dd></dl>

<dl class="function">
<dt id="waveplugs.infoitem.handle_infosize">
<tt class="descclassname">waveplugs.infoitem.</tt><tt class="descname">handle_infosize</tt><big>(</big><em>bot</em>, <em>ievent</em><big>)</big><a class="headerlink" href="#waveplugs.infoitem.handle_infosize" title="Permalink to this definition">¶</a></dt>
<dd>info-size .. show number of information items.</dd></dl>

<dl class="function">
<dt id="waveplugs.infoitem.handle_question">
<tt class="descclassname">waveplugs.infoitem.</tt><tt class="descname">handle_question</tt><big>(</big><em>bot</em>, <em>ievent</em><big>)</big><a class="headerlink" href="#waveplugs.infoitem.handle_question" title="Permalink to this definition">¶</a></dt>
<dd>?&lt;keyword&gt; .. ask for information item description.</dd></dl>

<dl class="function">
<dt id="waveplugs.infoitem.handle_searchdescr">
<tt class="descclassname">waveplugs.infoitem.</tt><tt class="descname">handle_searchdescr</tt><big>(</big><em>bot</em>, <em>ievent</em><big>)</big><a class="headerlink" href="#waveplugs.infoitem.handle_searchdescr" title="Permalink to this definition">¶</a></dt>
<dd>info-sd &lt;txttosearchfor&gt; .. search information items descriptions.</dd></dl>

<dl class="function">
<dt id="waveplugs.infoitem.handle_searchitem">
<tt class="descclassname">waveplugs.infoitem.</tt><tt class="descname">handle_searchitem</tt><big>(</big><em>bot</em>, <em>ievent</em><big>)</big><a class="headerlink" href="#waveplugs.infoitem.handle_searchitem" title="Permalink to this definition">¶</a></dt>
<dd>info-si &lt;txt&gt; .. search information keywords</dd></dl>

<dl class="function">
<dt id="waveplugs.infoitem.handle_showids">
<tt class="descclassname">waveplugs.infoitem.</tt><tt class="descname">handle_showids</tt><big>(</big><em>bot</em>, <em>ievent</em><big>)</big><a class="headerlink" href="#waveplugs.infoitem.handle_showids" title="Permalink to this definition">¶</a></dt>
<dd>showid &lt;keyword&gt; .. show ids of item descriptions.</dd></dl>

<dl class="function">
<dt id="waveplugs.infoitem.size">
<tt class="descclassname">waveplugs.infoitem.</tt><tt class="descname">size</tt><big>(</big><big>)</big><a class="headerlink" href="#waveplugs.infoitem.size" title="Permalink to this definition">¶</a></dt>
<dd>return number of infoitems.</dd></dl>

</div>
<div class="section" id="code">
<h2>code<a class="headerlink" href="#code" title="Permalink to this headline">¶</a></h2>
<div class="highlight-python"><table class="highlighttable"><tr><td class="linenos"><pre>  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287</pre></td><td class="code"><div class="highlight"><pre><span class="c"># waveplugs/infoitem.py</span>
<span class="c">#</span>
<span class="c">#</span>

<span class="sd">&quot;&quot;&quot; </span>
<span class="sd">    information items .. use !learn &lt;item&gt; is &lt;description&gt; to add an item .. </span>
<span class="sd">    use !? &lt;item&gt; to query the infoitems database.</span>
<span class="sd">&quot;&quot;&quot;</span>

<span class="c">## gozerlib unports</span>

<span class="kn">from</span> <span class="nn">gozerlib.tests</span> <span class="kn">import</span> <span class="n">tests</span>
<span class="kn">from</span> <span class="nn">gozerlib.commands</span> <span class="kn">import</span> <span class="n">cmnds</span>
<span class="kn">from</span> <span class="nn">gozerlib.examples</span> <span class="kn">import</span> <span class="n">examples</span>
<span class="kn">from</span> <span class="nn">gozerlib.persist.persist</span> <span class="kn">import</span> <span class="n">Persist</span>
<span class="kn">from</span> <span class="nn">gozerlib.utils.exception</span> <span class="kn">import</span> <span class="n">handle_exception</span>
<span class="kn">from</span> <span class="nn">gozerlib.aliases</span> <span class="kn">import</span> <span class="n">getaliases</span>
<span class="kn">from</span> <span class="nn">gozerlib.aliases</span> <span class="kn">import</span> <span class="n">aliasset</span>

<span class="c">## google imports</span>
   
<span class="kn">from</span> <span class="nn">google.appengine.ext</span> <span class="kn">import</span> <span class="n">db</span>

<span class="c">## basic imports</span>

<span class="kn">from</span> <span class="nn">datetime</span> <span class="kn">import</span> <span class="n">datetime</span>
<span class="kn">from</span> <span class="nn">time</span> <span class="kn">import</span> <span class="n">localtime</span>

<span class="kn">import</span> <span class="nn">thread</span>
<span class="kn">import</span> <span class="nn">os</span>
<span class="kn">import</span> <span class="nn">time</span>
<span class="kn">import</span> <span class="nn">logging</span>

<span class="k">class</span> <span class="nc">InfoItem</span><span class="p">(</span><span class="n">db</span><span class="o">.</span><span class="n">Expando</span><span class="p">):</span>

    <span class="n">item</span> <span class="o">=</span> <span class="n">db</span><span class="o">.</span><span class="n">StringProperty</span><span class="p">(</span><span class="n">required</span><span class="o">=</span><span class="bp">True</span><span class="p">)</span>
    <span class="n">description</span> <span class="o">=</span> <span class="n">db</span><span class="o">.</span><span class="n">StringProperty</span><span class="p">(</span><span class="n">required</span><span class="o">=</span><span class="bp">True</span><span class="p">)</span>
    <span class="n">creator</span> <span class="o">=</span> <span class="n">db</span><span class="o">.</span><span class="n">StringProperty</span><span class="p">()</span>
    <span class="n">channel</span> <span class="o">=</span> <span class="n">db</span><span class="o">.</span><span class="n">StringProperty</span><span class="p">()</span>
    <span class="n">createtime</span> <span class="o">=</span> <span class="n">db</span><span class="o">.</span><span class="n">DateTimeProperty</span><span class="p">()</span>
    <span class="n">public</span> <span class="o">=</span> <span class="n">db</span><span class="o">.</span><span class="n">BooleanProperty</span><span class="p">(</span><span class="n">default</span><span class="o">=</span><span class="bp">True</span><span class="p">)</span>
   
<span class="k">class</span> <span class="nc">InfoItemsDb</span><span class="p">(</span><span class="nb">object</span><span class="p">):</span>

    <span class="sd">&quot;&quot;&quot; information items &quot;&quot;&quot;</span>

    <span class="k">def</span> <span class="nf">add</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">item</span><span class="p">,</span> <span class="n">description</span><span class="p">,</span> <span class="n">userhost</span><span class="p">,</span> <span class="n">ttime</span><span class="p">,</span> <span class="n">channel</span><span class="o">=</span><span class="s">&quot;&quot;</span><span class="p">,</span> <span class="n">name</span><span class="o">=</span><span class="s">&quot;&quot;</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot; add an item &quot;&quot;&quot;</span>
        <span class="n">item</span> <span class="o">=</span> <span class="n">item</span><span class="o">.</span><span class="n">lower</span><span class="p">()</span>
        <span class="n">result</span> <span class="o">=</span> <span class="mf">0</span>

        <span class="k">try</span><span class="p">:</span>
            <span class="n">infoitem</span> <span class="o">=</span> <span class="n">InfoItem</span><span class="p">(</span><span class="n">item</span><span class="o">=</span><span class="n">item</span><span class="p">,</span> <span class="n">description</span><span class="o">=</span><span class="n">description</span><span class="p">)</span>
            <span class="n">infoitem</span><span class="o">.</span><span class="n">creator</span> <span class="o">=</span> <span class="n">userhost</span>
            <span class="n">infoitem</span><span class="o">.</span><span class="n">channel</span> <span class="o">=</span> <span class="n">channel</span>
            <span class="n">infoitem</span><span class="o">.</span><span class="n">createtime</span> <span class="o">=</span> <span class="n">datetime</span><span class="o">.</span><span class="n">fromtimestamp</span><span class="p">(</span><span class="n">ttime</span><span class="p">)</span>
            <span class="n">infoitem</span><span class="o">.</span><span class="n">put</span><span class="p">()</span>
            <span class="n">result</span> <span class="o">=</span> <span class="n">infoitem</span><span class="o">.</span><span class="n">key</span><span class="p">()</span><span class="o">.</span><span class="n">id</span><span class="p">()</span>
        <span class="k">except</span> <span class="ne">Exception</span><span class="p">,</span> <span class="n">ex</span><span class="p">:</span>
            <span class="n">logging</span><span class="o">.</span><span class="n">error</span><span class="p">(</span><span class="s">&quot;can&#39;t add item: </span><span class="si">%s</span><span class="s">&quot;</span> <span class="o">%</span> <span class="nb">str</span><span class="p">(</span><span class="n">ex</span><span class="p">))</span>
            <span class="k">raise</span> <span class="n">ex</span>

        <span class="k">return</span> <span class="n">result</span>

    <span class="k">def</span> <span class="nf">get</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">item</span><span class="p">):</span>

        <span class="sd">&quot;&quot;&quot; get infoitems. &quot;&quot;&quot;</span>

        <span class="n">item</span> <span class="o">=</span> <span class="n">item</span><span class="o">.</span><span class="n">lower</span><span class="p">()</span>
        <span class="n">result</span> <span class="o">=</span> <span class="n">InfoItem</span><span class="o">.</span><span class="n">all</span><span class="p">()</span><span class="o">.</span><span class="n">filter</span><span class="p">(</span><span class="s">&#39;item =&#39;</span><span class="p">,</span> <span class="n">item</span><span class="p">)</span><span class="o">.</span><span class="n">fetch</span><span class="p">(</span><span class="mf">1000</span><span class="p">)</span>
        <span class="k">return</span> <span class="n">result</span>

    <span class="k">def</span> <span class="nf">delete</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">indexnr</span><span class="p">):</span>

        <span class="sd">&quot;&quot;&quot; delete item with indexnr.  &quot;&quot;&quot;</span>
        
        <span class="n">item</span> <span class="o">=</span> <span class="n">InfoItem</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="n">indexnr</span><span class="p">)</span>

        <span class="k">if</span> <span class="n">item</span><span class="p">:</span>
            <span class="n">item</span><span class="o">.</span><span class="n">delete</span><span class="p">()</span>
            <span class="k">return</span> <span class="bp">True</span>

        <span class="k">return</span> <span class="bp">False</span>

    <span class="k">def</span> <span class="nf">size</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>

        <span class="sd">&quot;&quot;&quot; return number of items &quot;&quot;&quot;</span>

        <span class="k">return</span> <span class="n">InfoItem</span><span class="o">.</span><span class="n">all</span><span class="p">()</span><span class="o">.</span><span class="n">count</span><span class="p">()</span>

    <span class="k">def</span> <span class="nf">searchitem</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">search</span><span class="p">):</span>

        <span class="sd">&quot;&quot;&quot; search items. &quot;&quot;&quot;</span>

        <span class="n">r</span> <span class="o">=</span> <span class="p">[]</span>

        <span class="n">result</span> <span class="o">=</span> <span class="n">InfoItem</span><span class="o">.</span><span class="n">all</span><span class="p">()</span><span class="o">.</span><span class="n">fetch</span><span class="p">(</span><span class="mf">1000</span><span class="p">)</span>

        <span class="k">for</span> <span class="n">res</span> <span class="ow">in</span> <span class="n">result</span><span class="p">:</span>
            <span class="k">if</span> <span class="n">search</span> <span class="ow">in</span> <span class="n">res</span><span class="o">.</span><span class="n">item</span><span class="p">:</span>
                <span class="n">r</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">res</span><span class="p">)</span>

        <span class="k">return</span> <span class="n">r</span>

    <span class="k">def</span> <span class="nf">searchdescr</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">search</span><span class="p">):</span>

        <span class="sd">&quot;&quot;&quot; search descriptions. &quot;&quot;&quot;</span>

        <span class="n">r</span> <span class="o">=</span> <span class="p">[]</span>
        <span class="n">result</span> <span class="o">=</span> <span class="n">InfoItem</span><span class="o">.</span><span class="n">all</span><span class="p">()</span><span class="o">.</span><span class="n">fetch</span><span class="p">(</span><span class="mf">1000</span><span class="p">)</span>

        <span class="k">for</span> <span class="n">res</span> <span class="ow">in</span> <span class="n">result</span><span class="p">:</span>
            <span class="k">if</span> <span class="n">search</span> <span class="ow">in</span> <span class="n">res</span><span class="o">.</span><span class="n">description</span><span class="p">:</span>
                <span class="n">r</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">res</span><span class="p">)</span>

        <span class="k">return</span> <span class="n">r</span>


<span class="n">info</span> <span class="o">=</span> <span class="n">InfoItemsDb</span><span class="p">()</span>

<span class="k">assert</span><span class="p">(</span><span class="n">info</span><span class="p">)</span>

<span class="k">def</span> <span class="nf">size</span><span class="p">():</span>

    <span class="sd">&quot;&quot;&quot; return number of infoitems. &quot;&quot;&quot;</span>

    <span class="k">return</span> <span class="n">info</span><span class="o">.</span><span class="n">size</span><span class="p">()</span>

<span class="k">def</span> <span class="nf">handle_infosize</span><span class="p">(</span><span class="n">bot</span><span class="p">,</span> <span class="n">ievent</span><span class="p">):</span>

    <span class="sd">&quot;&quot;&quot; info-size .. show number of information items. &quot;&quot;&quot;</span>

    <span class="n">ievent</span><span class="o">.</span><span class="n">reply</span><span class="p">(</span><span class="s">&quot;we have </span><span class="si">%s</span><span class="s"> infoitems&quot;</span> <span class="o">%</span> <span class="n">info</span><span class="o">.</span><span class="n">size</span><span class="p">())</span>

<span class="n">cmnds</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="s">&#39;info-size&#39;</span><span class="p">,</span> <span class="n">handle_infosize</span><span class="p">,</span> <span class="p">[</span><span class="s">&#39;USER&#39;</span><span class="p">,</span> <span class="s">&#39;WEB&#39;</span><span class="p">,</span> <span class="s">&#39;CLOUD&#39;</span><span class="p">])</span>
<span class="n">examples</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="s">&#39;info-size&#39;</span><span class="p">,</span> <span class="s">&#39;show number of infoitems&#39;</span><span class="p">,</span> <span class="s">&#39;info-size&#39;</span><span class="p">)</span>

<span class="k">def</span> <span class="nf">handle_addinfoitem</span><span class="p">(</span><span class="n">bot</span><span class="p">,</span> <span class="n">ievent</span><span class="p">):</span>

    <span class="sd">&quot;&quot;&quot; learn &lt;keyword&gt; is &lt;description&gt; .. add information item &quot;&quot;&quot;</span>

    <span class="k">try</span><span class="p">:</span>
        <span class="p">(</span><span class="n">what</span><span class="p">,</span> <span class="n">description</span><span class="p">)</span> <span class="o">=</span> <span class="n">ievent</span><span class="o">.</span><span class="n">rest</span><span class="o">.</span><span class="n">split</span><span class="p">(</span><span class="s">&#39; is &#39;</span><span class="p">,</span> <span class="mf">1</span><span class="p">)</span>
    <span class="k">except</span> <span class="ne">ValueError</span><span class="p">:</span>
        <span class="n">ievent</span><span class="o">.</span><span class="n">reply</span><span class="p">(</span><span class="s">&#39;&lt;item&gt; is &lt;description&gt;&#39;</span><span class="p">)</span>
        <span class="k">return</span>

    <span class="n">what</span> <span class="o">=</span> <span class="n">what</span><span class="o">.</span><span class="n">strip</span><span class="p">()</span>
    <span class="n">ret</span> <span class="o">=</span> <span class="n">info</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="n">what</span><span class="p">,</span> <span class="n">description</span><span class="p">,</span> <span class="n">ievent</span><span class="o">.</span><span class="n">userhost</span><span class="p">,</span> <span class="n">time</span><span class="o">.</span><span class="n">time</span><span class="p">())</span>

    <span class="k">if</span> <span class="n">ret</span><span class="p">:</span>
        <span class="n">ievent</span><span class="o">.</span><span class="n">reply</span><span class="p">(</span><span class="s">&#39;item added&#39;</span><span class="p">)</span>
    <span class="k">else</span><span class="p">:</span>
        <span class="n">ievent</span><span class="o">.</span><span class="n">reply</span><span class="p">(</span><span class="s">&#39;unable to add item&#39;</span><span class="p">)</span>

<span class="n">cmnds</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="s">&#39;info-learn&#39;</span><span class="p">,</span> <span class="n">handle_addinfoitem</span><span class="p">,</span> <span class="p">[</span><span class="s">&#39;USER&#39;</span><span class="p">,</span> <span class="p">],</span> <span class="n">allowqueue</span><span class="o">=</span><span class="bp">False</span><span class="p">)</span>
<span class="n">examples</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="s">&#39;learn&#39;</span><span class="p">,</span> <span class="s">&#39;add description to item&#39;</span><span class="p">,</span> <span class="s">&#39;learn dunk is top&#39;</span><span class="p">)</span>
<span class="n">aliasset</span><span class="p">(</span><span class="s">&#39;learn&#39;</span><span class="p">,</span> <span class="s">&#39;info-learn&#39;</span><span class="p">)</span>

<span class="k">def</span> <span class="nf">handle_question</span><span class="p">(</span><span class="n">bot</span><span class="p">,</span> <span class="n">ievent</span><span class="p">):</span>

    <span class="sd">&quot;&quot;&quot; ?&lt;keyword&gt; .. ask for information item description. &quot;&quot;&quot;</span>

    <span class="n">what</span> <span class="o">=</span> <span class="n">ievent</span><span class="o">.</span><span class="n">rest</span>

    <span class="k">if</span> <span class="ow">not</span> <span class="n">what</span><span class="p">:</span>
        <span class="n">ievent</span><span class="o">.</span><span class="n">reply</span><span class="p">(</span><span class="s">&#39;i need a argument&#39;</span><span class="p">)</span>
        <span class="k">return</span>

    <span class="n">what</span> <span class="o">=</span> <span class="n">what</span><span class="o">.</span><span class="n">strip</span><span class="p">()</span><span class="o">.</span><span class="n">lower</span><span class="p">()</span>
    <span class="n">infoitems</span> <span class="o">=</span> <span class="n">info</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="n">what</span><span class="p">)</span>
    <span class="n">result</span> <span class="o">=</span> <span class="p">[]</span>

    <span class="k">for</span> <span class="n">item</span> <span class="ow">in</span> <span class="n">infoitems</span><span class="p">:</span>
        <span class="n">result</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">item</span><span class="o">.</span><span class="n">description</span><span class="p">)</span>

    <span class="k">if</span> <span class="n">result</span><span class="p">:</span>
        <span class="n">ievent</span><span class="o">.</span><span class="n">reply</span><span class="p">(</span><span class="s">&quot;</span><span class="si">%s</span><span class="s"> is &quot;</span> <span class="o">%</span> <span class="n">what</span><span class="p">,</span> <span class="n">result</span><span class="p">)</span>
    <span class="k">else</span><span class="p">:</span>
        <span class="n">ievent</span><span class="o">.</span><span class="n">reply</span><span class="p">(</span><span class="s">&#39;nothing known about </span><span class="si">%s</span><span class="s">&#39;</span> <span class="o">%</span> <span class="n">what</span><span class="p">)</span>

<span class="n">cmnds</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="s">&#39;info-?&#39;</span><span class="p">,</span> <span class="n">handle_question</span><span class="p">,</span> <span class="p">[</span><span class="s">&#39;USER&#39;</span><span class="p">,</span> <span class="p">],</span> <span class="n">allowqueue</span><span class="o">=</span><span class="bp">True</span><span class="p">)</span>
<span class="n">examples</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="s">&#39;info-?&#39;</span><span class="p">,</span> <span class="s">&#39;show infoitems of &lt;what&gt;&#39;</span><span class="p">,</span> <span class="s">&#39;? test&#39;</span><span class="p">)</span>
<span class="n">aliasset</span><span class="p">(</span><span class="s">&#39;?&#39;</span><span class="p">,</span> <span class="s">&#39;info-?&#39;</span><span class="p">)</span>

<span class="k">def</span> <span class="nf">handle_showids</span><span class="p">(</span><span class="n">bot</span><span class="p">,</span> <span class="n">ievent</span><span class="p">):</span>

    <span class="sd">&quot;&quot;&quot; showid &lt;keyword&gt; .. show ids of item descriptions. &quot;&quot;&quot;</span>

    <span class="n">what</span> <span class="o">=</span> <span class="n">ievent</span><span class="o">.</span><span class="n">rest</span>

    <span class="k">if</span> <span class="ow">not</span> <span class="n">what</span><span class="p">:</span>
        <span class="n">ievent</span><span class="o">.</span><span class="n">reply</span><span class="p">(</span><span class="s">&#39;&lt;item&gt;&#39;</span><span class="p">)</span>
        <span class="k">return</span>

    <span class="n">what</span> <span class="o">=</span> <span class="n">what</span><span class="o">.</span><span class="n">strip</span><span class="p">()</span><span class="o">.</span><span class="n">lower</span><span class="p">()</span>
    <span class="n">infoitems</span> <span class="o">=</span> <span class="n">info</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="n">what</span><span class="p">)</span>
    <span class="n">result</span> <span class="o">=</span> <span class="p">[]</span>

    <span class="k">for</span> <span class="n">item</span> <span class="ow">in</span> <span class="n">infoitems</span><span class="p">:</span>
        <span class="n">result</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="s">&quot;</span><span class="si">%s</span><span class="s"> (</span><span class="si">%s</span><span class="s">)&quot;</span> <span class="o">%</span> <span class="p">(</span><span class="n">item</span><span class="o">.</span><span class="n">description</span><span class="p">,</span> <span class="n">item</span><span class="o">.</span><span class="n">key</span><span class="p">()</span><span class="o">.</span><span class="n">id</span><span class="p">()))</span>

    <span class="k">if</span> <span class="n">result</span><span class="p">:</span>
        <span class="n">ievent</span><span class="o">.</span><span class="n">reply</span><span class="p">(</span><span class="s">&quot;ids of </span><span class="si">%s</span><span class="s">: &quot;</span> <span class="o">%</span> <span class="n">what</span><span class="p">,</span> <span class="n">result</span><span class="p">)</span>
    <span class="k">else</span><span class="p">:</span>
        <span class="n">ievent</span><span class="o">.</span><span class="n">reply</span><span class="p">(</span><span class="s">&#39;nothing known about </span><span class="si">%s</span><span class="s">&#39;</span> <span class="o">%</span> <span class="n">what</span><span class="p">)</span>

<span class="n">cmnds</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="s">&#39;info-showids&#39;</span><span class="p">,</span> <span class="n">handle_showids</span><span class="p">,</span> <span class="p">[</span><span class="s">&#39;USER&#39;</span><span class="p">,</span> <span class="p">],</span> <span class="n">allowqueue</span><span class="o">=</span><span class="bp">True</span><span class="p">)</span>
<span class="n">examples</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="s">&#39;info-showids&#39;</span><span class="p">,</span> <span class="s">&#39;show ids of infoitems descriptions&#39;</span><span class="p">,</span> <span class="s">&#39;info-showids gozerwave&#39;</span><span class="p">)</span>

<span class="k">def</span> <span class="nf">handle_forget</span><span class="p">(</span><span class="n">bot</span><span class="p">,</span> <span class="n">ievent</span><span class="p">):</span>

    <span class="sd">&quot;&quot;&quot; </span>
<span class="sd">        forget &lt;keyword&gt; &lt;txttomatch&gt; .. remove information item where \</span>
<span class="sd">        description matches txt given.</span>
<span class="sd">    &quot;&quot;&quot;</span>

    <span class="k">try</span><span class="p">:</span>
        <span class="n">indexnr</span> <span class="o">=</span> <span class="nb">int</span><span class="p">(</span><span class="n">ievent</span><span class="o">.</span><span class="n">args</span><span class="p">[</span><span class="mf">0</span><span class="p">])</span>
    <span class="k">except</span> <span class="p">(</span><span class="ne">IndexError</span><span class="p">,</span> <span class="ne">ValueError</span><span class="p">):</span>
        <span class="n">ievent</span><span class="o">.</span><span class="n">reply</span><span class="p">(</span><span class="s">&quot;&lt;indexnr&gt;&quot;</span><span class="p">)</span>
        <span class="k">return</span>

    <span class="n">nrtimes</span> <span class="o">=</span> <span class="n">info</span><span class="o">.</span><span class="n">delete</span><span class="p">(</span><span class="n">indexnr</span><span class="p">)</span>

    <span class="k">if</span> <span class="n">nrtimes</span><span class="p">:</span>
        <span class="n">ievent</span><span class="o">.</span><span class="n">reply</span><span class="p">(</span><span class="s">&#39;item deleted&#39;</span><span class="p">)</span>
    <span class="k">else</span><span class="p">:</span>
        <span class="n">ievent</span><span class="o">.</span><span class="n">reply</span><span class="p">(</span><span class="s">&#39;delete </span><span class="si">%s</span><span class="s"> of </span><span class="si">%s</span><span class="s"> failed&#39;</span> <span class="o">%</span> <span class="p">(</span><span class="n">txt</span><span class="p">,</span> <span class="n">what</span><span class="p">))</span>

<span class="n">cmnds</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="s">&#39;info-forget&#39;</span><span class="p">,</span> <span class="n">handle_forget</span><span class="p">,</span> <span class="p">[</span><span class="s">&#39;FORGET&#39;</span><span class="p">,</span> <span class="s">&#39;OPER&#39;</span><span class="p">])</span>
<span class="n">examples</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="s">&#39;info-forget&#39;</span><span class="p">,</span> <span class="s">&#39;forget &lt;item&gt; containing &lt;txt&gt;&#39;</span><span class="p">,</span> <span class="s">&#39;info-forget 1001&#39;</span><span class="p">)</span>
<span class="n">aliasset</span><span class="p">(</span><span class="s">&#39;forget&#39;</span><span class="p">,</span> <span class="s">&#39;info-forget&#39;</span><span class="p">)</span>

<span class="k">def</span> <span class="nf">handle_searchdescr</span><span class="p">(</span><span class="n">bot</span><span class="p">,</span> <span class="n">ievent</span><span class="p">):</span>

    <span class="sd">&quot;&quot;&quot; info-sd &lt;txttosearchfor&gt; .. search information items descriptions. &quot;&quot;&quot;</span>

    <span class="k">if</span> <span class="ow">not</span> <span class="n">ievent</span><span class="o">.</span><span class="n">rest</span><span class="p">:</span>
        <span class="n">ievent</span><span class="o">.</span><span class="n">missing</span><span class="p">(</span><span class="s">&#39;&lt;txt&gt;&#39;</span><span class="p">)</span>
        <span class="k">return</span>
    <span class="k">else</span><span class="p">:</span>
        <span class="n">what</span> <span class="o">=</span> <span class="n">ievent</span><span class="o">.</span><span class="n">rest</span>

    <span class="n">what</span> <span class="o">=</span> <span class="n">what</span><span class="o">.</span><span class="n">strip</span><span class="p">()</span><span class="o">.</span><span class="n">lower</span><span class="p">()</span>
    <span class="n">result</span> <span class="o">=</span> <span class="n">info</span><span class="o">.</span><span class="n">searchdescr</span><span class="p">(</span><span class="n">what</span><span class="p">)</span>

    <span class="k">if</span> <span class="n">result</span><span class="p">:</span> 
        <span class="n">res</span> <span class="o">=</span> <span class="p">[]</span>

        <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="n">result</span><span class="p">:</span>
            <span class="n">res</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="s">&quot;[</span><span class="si">%s</span><span class="s">] </span><span class="si">%s</span><span class="s">&quot;</span> <span class="o">%</span> <span class="p">(</span><span class="n">i</span><span class="o">.</span><span class="n">item</span><span class="p">,</span> <span class="n">i</span><span class="o">.</span><span class="n">description</span><span class="p">))</span>

        <span class="n">ievent</span><span class="o">.</span><span class="n">reply</span><span class="p">(</span><span class="s">&quot;the following matches </span><span class="si">%s</span><span class="s">: &quot;</span> <span class="o">%</span> <span class="n">what</span><span class="p">,</span> <span class="n">res</span><span class="p">,</span> <span class="n">dot</span><span class="o">=</span><span class="bp">True</span><span class="p">)</span>

    <span class="k">else</span><span class="p">:</span>
        <span class="n">ievent</span><span class="o">.</span><span class="n">reply</span><span class="p">(</span><span class="s">&#39;none found&#39;</span><span class="p">)</span>

<span class="n">cmnds</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="s">&#39;info-sd&#39;</span><span class="p">,</span> <span class="n">handle_searchdescr</span><span class="p">,</span> <span class="p">[</span><span class="s">&#39;USER&#39;</span><span class="p">,</span> <span class="s">&#39;WEB&#39;</span><span class="p">,</span> <span class="s">&#39;CLOUD&#39;</span><span class="p">])</span>
<span class="n">examples</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="s">&#39;info-sd&#39;</span><span class="p">,</span> <span class="s">&#39;info-sd &lt;txt&gt; ..  search description of infoitems&#39;</span><span class="p">,</span> <span class="s">&#39;info-sd http&#39;</span><span class="p">)</span>

<span class="k">def</span> <span class="nf">handle_searchitem</span><span class="p">(</span><span class="n">bot</span><span class="p">,</span> <span class="n">ievent</span><span class="p">):</span>

    <span class="sd">&quot;&quot;&quot; info-si &lt;txt&gt; .. search information keywords &quot;&quot;&quot;</span>

    <span class="k">if</span> <span class="ow">not</span> <span class="n">ievent</span><span class="o">.</span><span class="n">rest</span><span class="p">:</span>
        <span class="n">ievent</span><span class="o">.</span><span class="n">missing</span><span class="p">(</span><span class="s">&#39;&lt;txt&gt;&#39;</span><span class="p">)</span>
        <span class="k">return</span>
    <span class="k">else</span><span class="p">:</span>
        <span class="n">what</span> <span class="o">=</span> <span class="n">ievent</span><span class="o">.</span><span class="n">rest</span>

    <span class="n">what</span> <span class="o">=</span> <span class="n">what</span><span class="o">.</span><span class="n">strip</span><span class="p">()</span><span class="o">.</span><span class="n">lower</span><span class="p">()</span>
    <span class="n">result</span> <span class="o">=</span> <span class="n">info</span><span class="o">.</span><span class="n">searchitem</span><span class="p">(</span><span class="n">what</span><span class="p">)</span>

    <span class="k">if</span> <span class="n">result</span><span class="p">:</span>
        <span class="n">res</span> <span class="o">=</span> <span class="p">[]</span>

        <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="n">result</span><span class="p">:</span>
            <span class="n">res</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="s">&quot;[</span><span class="si">%s</span><span class="s">] </span><span class="si">%s</span><span class="s">&quot;</span> <span class="o">%</span> <span class="p">(</span><span class="n">i</span><span class="o">.</span><span class="n">item</span><span class="p">,</span> <span class="n">i</span><span class="o">.</span><span class="n">description</span><span class="p">))</span>

        <span class="n">ievent</span><span class="o">.</span><span class="n">reply</span><span class="p">(</span><span class="s">&quot;the following matches </span><span class="si">%s</span><span class="s">: &quot;</span> <span class="o">%</span> <span class="n">what</span><span class="p">,</span> <span class="n">res</span><span class="p">,</span> <span class="n">dot</span><span class="o">=</span><span class="bp">True</span><span class="p">)</span>

    <span class="k">else</span><span class="p">:</span>
        <span class="n">ievent</span><span class="o">.</span><span class="n">reply</span><span class="p">(</span><span class="s">&#39;none found&#39;</span><span class="p">)</span>

<span class="n">cmnds</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="s">&#39;info-si&#39;</span><span class="p">,</span> <span class="n">handle_searchitem</span><span class="p">,</span> <span class="p">[</span><span class="s">&#39;USER&#39;</span><span class="p">,</span> <span class="s">&#39;WEB&#39;</span><span class="p">,</span> <span class="s">&#39;CLOUD&#39;</span><span class="p">])</span>
<span class="n">examples</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="s">&#39;info-si&#39;</span><span class="p">,</span> <span class="s">&#39;info-si &lt;txt&gt; ..  search the infoitems keys&#39;</span><span class="p">,</span> <span class="s">&#39;info-si test&#39;</span><span class="p">)</span>
</pre></div>
</td></tr></table></div>
</div>
</div>


          </div>
        </div>
      </div>
      <div class="sphinxsidebar">
        <div class="sphinxsidebarwrapper">
            <h3><a href="../index.html">Table Of Contents</a></h3>
            <ul>
<li><a class="reference external" href="">infoitem</a><ul>
<li><a class="reference external" href="#module-waveplugs.infoitem">description</a></li>
<li><a class="reference external" href="#code">code</a></li>
</ul>
</li>
</ul>

            <h4>Previous topic</h4>
            <p class="topless"><a href="gcalc.html"
                                  title="previous chapter">gcalc</a></p>
            <h4>Next topic</h4>
            <p class="topless"><a href="rss.html"
                                  title="next chapter">rss</a></p>
            <h3>This Page</h3>
            <ul class="this-page-menu">
              <li><a href="../_sources/waveplugs/infoitem.txt"
                     rel="nofollow">Show Source</a></li>
            </ul>
          <div id="searchbox" style="display: none">
            <h3>Quick search</h3>
              <form class="search" action="../search.html" method="get">
                <input type="text" name="q" size="18" />
                <input type="submit" value="Go" />
                <input type="hidden" name="check_keywords" value="yes" />
                <input type="hidden" name="area" value="default" />
              </form>
              <p class="searchtip" style="font-size: 90%">
              Enter search terms or a module, class or function name.
              </p>
          </div>
          <script type="text/javascript">$('#searchbox').show(0);</script>
        </div>
      </div>
      <div class="clearer"></div>
    </div>
    <div class="related">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="../genindex.html" title="General Index"
             >index</a></li>
        <li class="right" >
          <a href="../modindex.html" title="Global Module Index"
             >modules</a> |</li>
        <li class="right" >
          <a href="rss.html" title="rss"
             >next</a> |</li>
        <li class="right" >
          <a href="gcalc.html" title="gcalc"
             >previous</a> |</li>
        <li><a href="../index.html">GOZERWAVE v0.1 BETA documentation</a> &raquo;</li> 
      </ul>
    </div>
    <div class="footer">
      &copy; Copyright 2009, Bart Thate.
      Last updated on Nov 14, 2009.
      Created using <a href="http://sphinx.pocoo.org/">Sphinx</a> 0.6.3.
    </div>
  </body>
</html>